import wepy from 'wepy';
import util from './util';
import tip from './tip'

// const baseUrl = 'https://6e4a27a3.ngrok.io/';
const API_SECRET_KEY = 'null'
// 获取当前时间
const TIMESTAMP = util.getCurrentTime()
const SIGN = TIMESTAMP
// const TYPE = type
// const SIGN = md5.hex_md5((TIMESTAMP + API_SECRET_KEY).toLowerCase())

const wxRequest = async(params = {}, url) => {
    // tip.showLoad();
    let data = params.query || {};
    let header = {
        'Content-Type': 'application/json',
        'cookie': wepy.getStorageSync('sessionid')
    } || {}
    // data.type = TYPE;
    data.sign = SIGN;
    data.time = TIMESTAMP;
    let res = await wepy.request({
        url: url, //开发者服务器接口地址",
        data: data, //请求的参数",
        method: params.method || 'GET',
        // dataType: 'json', //如果设为json，会尝试对返回的数据做一次 JSON.parse
        header: header,
    });
    // tip.loaded();
    return res;
};

module.exports = {
    wxRequest
}